package maple

import scala.annotation.tailrec

object ListSumTest {
  def main(args: Array[String]): Unit = {
      val arr = ( 1 to 10).toList
      println(arr.sum)
      println(sum1(arr))
      println(sum2(arr))
  }

  def sum1(list: List[Int]):Int = {
    if(list ==Nil) 0
    else list.head + sum1(list.tail)
  }

//  @tailrec
  def sum2(list: List[Int]):Int = list match {

    case Nil => 0
    case h :: t => h +sum2(t)
  }
}
